<?php

include_once 'db/li.php';

@$updateTypes = $_REQUEST['updateType'];
@$goodsId = $_REQUEST['goodsId'];
@$typeId = $_REQUEST['typeId'];

@$updateGood = dbSelect('select goods.name as gName,type.id as tId,imgUrl from goods join type on goods.typeId=type.id where goods.id=:id',
					array('id'=>$goodsId));

@$updateType = dbSelect('select id,name from type where id=:id',array('id'=>$typeId));

include 'header.php';
?>
   		<div class='container'>
   			<div class='row'>
   				<div class='col-xs-2'>
   					<a href='index.php' class='btn btn-default btn-block'>返回首页</a>
   					<a href='goodsList.php' class='btn btn-default btn-block'>商品列表</a>
   					<a href='addGoodsType.php?addType=goods' class='btn btn-default btn-block'>添加商品</a>
   					<a href='typeList.php' class='btn btn-default btn-block'>类型列表</a>
   					<a href='addGoodsType.php?addType=type' class='btn btn-default btn-block'>添加商品类型</a>
   				</div>
   				<div class='col-xs-4'>
   					<div class='panel panel-primary'>
   						<div class='panel-heading'>
   							<?php if($updateTypes == "goods"){?>
   								<div class='panel-title'>编辑商品[<?php echo $updateGood['gName'];?>]</div>
   							<?php }else{?>
   								<div class='panel-title'>编辑商品类型[<?php echo $updateType['name'];?>]</div>
   							<?php }?>
   						</div>
   						<?php if($updateTypes == "goods"){?>
   							<form class='form-horizontal' action='updatePro.php?goodsId=<?php echo $goodsId;?>' method='post' enctype='multipart/form-data'>
   						<?php }else{?>
   							<form class='form-horizontal' action='updatePro.php?typeId=<?php echo $typeId;?>' method='post'>
   						<?php }?>
	   						<div class='panel-body'>
	   							<?php if(!empty($mes)){?>
   									<div class='alert alert-danger'>
   										<?php @print($mes);?>
   										<div class='close' data-dismiss='alert'>&times;</div>
   									</div>
	   							<?php }?>
	   							<?php if($updateTypes == "goods"){?>
	   								<input type='hidden' name='upType' value='name' />
	   								<div class='col-xs-8 col-xs-offset-2'>
	   									<img src='img/<?php echo $updateGood['imgUrl'];?>' class='updateGoodsImg' />
	   								</div>
	   								<div class='form-group'>
	   									<label class='col-xs-3 control-label' for='file'>图片</label>
	   									<div class='col-xs-9'>
	   										<input class='form-control' name='file' id='file' type='file' />
	   									</div>
	   								</div>
	   							<?php }else{?>
	   								<input type='hidden' name='upType' value='type' />
	   							<?php }?>
	   							<div class='form-group'>
	   								<label class='col-xs-3 control-label' for='name'>名称</label>
	   								<div class='col-xs-9'>
	   									<input class='form-control' name='name' id='name' type='text' value="<?php echo $updateTypes=='goods'?$updateGood['gName']:$updateType['name'];?>" required='required' />
	   								</div>
	   							</div>
	   							<?php if($updateTypes == "goods"){?>
		   							<div class='form-group'>
		   								<label class='col-xs-3 control-label' for='typeId'>类型</label>
		   								<div class='col-xs-9'>
		   									<select class='form-control' id='typeId' name='typeId'>
		   										<option>商品类型</option>
		   										<?php foreach($types as $type){?>
		   											<option value="<?php echo $type['id'];?>" <?php echo $type['id']==$updateGood['tId']?"selected='selected'":'';?>><?php echo $type['name'];?></option>
		   										<?php }?>
		   									</select>
		   								</div>
		   							</div>
		   						<?php }?>
	   						</div>
	   						<div class='panel-footer' style='padding-left:100px;'>
   								<button class='btn btn-primary' type='submit'>确定</button>
   								<?php if($updateTypes == "goods"){?>
   									<a href='goodsList.php' class='btn btn-default'>返回</a>
   								<?php }else{?>
   									<a href='typeList.php' class='btn btn-default'>返回</a>
   								<?php }?>
   							</div>
   						</form>
   					</div>
   				</div>
   			</div>
   		</div>
	   	<script src='db/previewImg.js'></script>
   	</body>
</html>
